cmake_minimum_required(VERSION 3.15)
project(detect_web_cpp)

set(CMAKE_CXX_STANDARD 17)

option(USE_RIVSINFERENCE "Use RivsInference" ON)
option(USE_RIVS_FFMPEG "use Rivs ffmpeg" ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
set(CMAKE_INSTALL_RPATH /opt/rivs/lib)

# OpenCV
find_package(OpenCV REQUIRED)

# TopsInference (same as detect_perf)
if (USE_RIVSINFERENCE)
    find_path(RIVSINFERENCE_INCLUDE_DIR RivsInference/RivsInferRuntime.h
            PATHS /opt/rivs/include $ENV{HOME}/enrigin_sdk/usr/include
            DOC "RivsInference include directory")

    find_path(RIVS_EXT_INCLUDE_DIR rivs/rivs_ext.h
            PATHS /opt/rivs/include $ENV{HOME}/enrigin_sdk/opt/rivs/include
            DOC "RivsInference include directory")

    find_library(RIVS_LIBS RivsInference
            PATHS /lib /opt/rivs/lib $ENV{HOME}/enrigin_sdk/usr/lib
            DOC "RivsInference library")
endif()

add_subdirectory(otl)
# Include directories
include_directories(
        ${OpenCV_INCLUDE_DIRS}
        ${RIVSINFERENCE_INCLUDE_DIR}
        ${RIVS_EXT_INCLUDE_DIR}
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${CMAKE_CURRENT_SOURCE_DIR}/otl
)

# Add local web server utilities (independent of detect_perf)
set(WEB_UTIL_SRCS
        web_server.cpp
        web_status_ui.cpp
        web_utils.cpp
)

# Executables
add_executable(yolov5_web
        yolov5_web.cpp
        ${WEB_UTIL_SRCS}
)

add_executable(yolox_web
        yolox_web.cpp
        ${WEB_UTIL_SRCS}
)

# Link libraries
foreach(tgt IN ITEMS yolov5_web yolox_web)
    target_link_libraries(${tgt}
            ${OpenCV_LIBS}
            ${RIVS_LIBS}
            otl
            pthread
    )
endforeach()
